<?php

class Form_ArtWork extends Zend_Form
{

    public function init()
    {
        $id = new Zend_Form_Element_Hidden("id");
        //$id->setLabel("Id: ");
        $id->setValue(0);
        $id->setRequired(true);
        $idValidator = new Zend_Validate_Int();
        $id->addValidator($idValidator);
        $this->addElement($id, "id");
        
        
        $name = new Zend_Form_Element_Text("name");
        $name->setLabel("Name: ");
        $nameValidator = new Zend_Validate_Alnum();
        //$name->addValidator($nameValidator);
        $this->addElement($name, "name");
        
        
        $artist = new Zend_Form_Element_Select("artist");
        $artist->setLabel("Artist: ");
        $artistValidator = new Zend_Validate_Int();
        $artist->addValidator($artistValidator);
        
        $table = new Model_DbTable_Artist();
        $artists = $table->fetchAll();
        foreach ($artists as $theArtist){
        	$artist->addMultiOption($theArtist->id, $theArtist->name);
        }
        $this->addElement($artist, "artist");
        
        
        $base_price = new Zend_Form_Element_Text("base_price");
        $base_price->setLabel("Base Price: ");
        $basePriceValidator = new Zend_Validate_Float();
        $base_price->addValidator($basePriceValidator);
        $this->addElement($base_price, "base_price");
        
        $rmb_price = new Zend_Form_Element_Text("rmb_price");
        $rmb_price->setLabel("Rmb Price: ");
        $rmb_price->setAttrib("onblur", "getOtherPrice();");
        $rmbPriceValidator = new Zend_Validate_Float();
        $rmb_price->addValidator($rmbPriceValidator);
        $this->addElement($rmb_price, "rmb_price");
        
        
        $usd_price = new Zend_Form_Element_Text("usd_price");
        $usd_price->setLabel("Usd Price: ");
        $usdPriceValidator = new Zend_Validate_Float();
        $usd_price->addValidator($usdPriceValidator);
        $this->addElement($usd_price, "usd_price");
        
        
        $uro_price = new Zend_Form_Element_Text("uro_price");
        $uro_price->setLabel("Uro Price: ");
        $uroPriceValidator = new Zend_Validate_Float();
        $uro_price->addValidator($uroPriceValidator);
        $this->addElement($uro_price, "uro_price");
        
        
        $knockdown_price = new Zend_Form_Element_Text("knockdown_price");
        $knockdown_price->setLabel("Knockdown Price: ");
        $knockdownValidator = new Zend_Validate_Float();
        $knockdown_price->addValidator($knockdownValidator);
        $this->addElement($knockdown_price, "knockdown_price");
        
        $knockdown_currency = new Zend_Form_Element_Radio("knockdown_currency");
        $knockdown_currency->addMultiOption("USD","USD");
        $knockdown_currency->addMultiOption("EUR","EUR");
        $knockdown_currency->addMultiOption("RMB","RMB");
        $knockdown_currency->setLabel("Knockdown Currency: ");
        $knockdown_currency->setAttrib("disabled","disabled");
        $this->addElement($knockdown_currency, "knockdown_currency");
        
        
        $date_of_creation = new Zend_Form_Element_Text("date_of_creation");
        $date_of_creation->setLabel("DateOfCreation: ");
        $dateValidator = new Zend_Validate_Date();
        $dateValidator->setFormat("YYYY");
        $date_of_creation->addValidator($dateValidator);
        $this->addElement($date_of_creation, "date_of_creation");
        
        
        $size = new Zend_Form_Element_Text("size");
        $size->setLabel("Size: ");
        $sizeValidator = new Zend_Validate_Regex('/^(\d+(?:\.\d)?)\s*x\s*(\d+(?:\.\d)?)(?:\s*cm)?(?:\s*x\s*(\d+(?:\.\d)?)(?:\s*cm))?$/');
        $size->addFilter(new Zend_Filter_StringToLower());
        $size->addFilter(new Zend_Filter_StringTrim());
        $size->addValidator($sizeValidator);
        $this->addElement($size, "size");
        
        
        $extra = new Zend_Form_Element_Select("category");
        $extra->setLabel("Category: ");
        $intValidator = new Zend_Validate_Int();
    	$table = new Model_DbTable_ArtworkCategory();
        $categories = $table->fetchAll("parent != 0");
        foreach ($categories as $category){
        	$extra->addMultiOption($category->id, $category->name);
        }
        $this->addElement($extra, "category");
        
        
        $photo = new Zend_Form_Element_File("photo");
        $photo->setLabel("Photo: ")->setRequired(true)
        	->setDestination(APPLICATION_PATH . "/../public/images/artwork_images/original/");
        $photoFilter = new Zend_Filter_File_Rename(md5(microtime()) . ".jpg");
        $photo->addFilter($photoFilter);
        $photoValidator = new Zend_Validate_File_Extension("jpg");
        $photo->addValidator($photoValidator);
        $this->addElement($photo, "photo");
        
         
        $intro = new Zend_Form_Element_Textarea("intro");
        $intro->setLabel("Intro: ");
        $intro->setAttrib("class", "ckeditor");
        $this->addElement($intro, "intro");
        
        
        $subject = new Zend_Form_Element_MultiCheckbox("subject");
        $subject->setLabel("Subject: ");
        //$subject->setSeparator("&nbsp;");
        $intValidator = new Zend_Validate_Int();
    	$table = new Model_DbTable_Subject();
        $subjects = $table->fetchAll();
        foreach ($subjects as $theSubject){
        	$subject->addMultiOption($theSubject->id, $theSubject->name);
        }
        $this->addElement($subject, "subject");
        
        
        $style = new Zend_Form_Element_MultiCheckbox("style");
        $style->setLabel("Style: ");
        //$style->setSeparator("&nbsp;");
        $intValidator = new Zend_Validate_Int();
    	$table = new Model_DbTable_Styles();
        $styles = $table->fetchAll();
        foreach ($styles as $theStyle){
        	$style->addMultiOption($theStyle->id, $theStyle->name);
        }
        $this->addElement($style, "style");
        
        
        $typical = new Zend_Form_Element_Select("typical");
        $typical->setLabel("Typical Artwork: ");
        $typical->addMultiOption("N", "普通作品");
        $typical->addMultiOption("Y", "代表作");
        $this->addElement($typical, "typical");
        
        
        
        $display_positions = new Zend_Form_Element_Select("display_positions");
        $display_positions->setLabel("Display Positions: ");
        $display_positions->addMultiOption(0, "默认（普通艺术品列表页）");
        $display_positions->addMultiOption(1, "首页推荐");
        $displayPositionValidator = new Zend_Validate_Int();
        $display_positions->addValidator($displayPositionValidator);
        $this->addElement($display_positions, "display_positions");
        
        
        $tags = new Zend_Form_Element_MultiCheckbox("tags");
        $tags->setLabel("Tags: ");
        //$tags->setSeparator("&nbsp;");
    	$table = new Model_DbTable_Tags();
        $tagss = $table->fetchAll();
        foreach ($tagss as $tag){
        	$tags->addMultiOption($tag->id, $tag->name);
        }
        $this->addElement($tags, "tags");
        
        
        $relational_works = new Zend_Form_Element_MultiCheckbox("relational_works");
        $relational_works->setLabel("Relational Works: ");
        //$relational_works->setSeparator("&nbsp;");
   		$table = new Model_DbTable_ArtWork();
        $artworks = $table->fetchAll();
        foreach ($artworks as $artwork){
        	$relational_works->addMultiOption($artwork->id, $artwork->name);
        }
        $this->addElement($relational_works, "relational_works");
        $display_order = new Zend_Form_Element_Text("display_order");
        $display_order->setLabel("DisplayOrder: ");
        $this->addElement($display_order, "display_order");
        
        
        $submit = new Zend_Form_Element_Submit("submit");
        $this->addElement($submit, "submit");
    }


}

